Skip to content

[rmodels] Use the per-bone normal matrices in CPU skinning again - #6434

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
b84330808:fix-cpu-skinning-normal-matrices
Nov 21, 2026
Merged

raysan5 merged 1 commit into
raysan5:masterfrom
b84330808:fix-cpu-skinning-normal-matrices

Conversation

@b84330808

@b84330808 b84330808 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

#6191 made UpdateModelAnimation() compute each bone's normal matrix once per update. #5921 was merged a week later from an older branch and, while switching the loop to Mesh *, put the per-vertex MatrixTranspose(MatrixInvert(model.boneMatrices[boneIndex])) back. So right now boneNormalMatrices is filled every update and never read, and every skinned vertex inverts up to 4 matrices again.

This is the one-line fix: use boneNormalMatrices[boneIndex] in the vertex loop.

UpdateModelAnimation() time per call with the example models (default material, so CPU skinning), median of 7 alternating runs, Windows 11, i7-9700, zig cc -O2, GLFW + OpenGL 3.3:

model before after
robot.glb (7218 verts) 359 us 103 us
cesium_man.m3d (14016 verts) 1320 us 303 us
greenman.glb (196 verts) 22.5 us 10.4 us
guy.iqm (224 verts) 11.6 us 8.7 us

Animated vertices and normals are bit-identical before and after (hashed animVertices/animNormals).

raysan5#6191 computes each bone's normal matrix once per update, but raysan5#5921
(merged later from an older branch) brought back the per-vertex
`MatrixTranspose(MatrixInvert(...))` call when it switched the loop to
`Mesh *`. Since then the normal matrices are computed and never used,
and every skinned vertex inverts up to four 4x4 matrices again.

Use `boneNormalMatrices[boneIndex]` in the vertex loop. The animated
vertices and normals are bit-identical.
@raysan5
raysan5 merged commit 54a3e96 into raysan5:master Nov 21, 2026
16 checks passed
@raysan5

raysan5 commented Nov 21, 2026

Copy link
Copy Markdown
Owner

@b84330808 oh, good catch! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants